package com.sk.skplanet.commute.parser;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import com.sk.skplanet.commute.vo.GetStationByRouteVo;
import com.sk.skplanet.commute.vo.GetStationByUidVo;

public class GetStationByUidParser extends SeoulBusAPIParser {
	List<GetStationByUidVo> result;
	
	public GetStationByUidParser(String rawdata) {
		super(rawdata);
	}
	
	@Override
	public List<?> parse() {
		result = new ArrayList<GetStationByUidVo>();
		
		try {
			XmlPullParserFactory parserCreator = XmlPullParserFactory.newInstance();
			XmlPullParser parser = parserCreator.newPullParser();

			parser.setInput(new StringReader(rawData));
			parser.next();
			
			int parserEvent = parser.getEventType();

			String tagName = "";
			GetStationByUidVo objectToAdd = null;

			while (parserEvent != XmlPullParser.END_DOCUMENT) {
				switch (parserEvent) {
				case XmlPullParser.START_DOCUMENT:
					break;
				case XmlPullParser.START_TAG:
					tagName = parser.getName();
					if(tagName.equals("itemList"))
						objectToAdd = new GetStationByUidVo();
					break;
				case XmlPullParser.END_TAG:
					if(parser.getName().equals("itemList")) {
						result.add(objectToAdd);
						objectToAdd = null;
					}
					break;
				case XmlPullParser.TEXT:
					String text = parser.getText();
					
					if(objectToAdd != null) {
						if(tagName.equals("stId"))
							objectToAdd.setStId(text);
						else if(tagName.equals("stNm"))
							objectToAdd.setStNm(text);
						else if(tagName.equals("arsId"))
							objectToAdd.setArsId(text);
						else if(tagName.equals("busRouteId"))
							objectToAdd.setBusRouteId(text);
						else if(tagName.equals("rtNm"))
							objectToAdd.setRtNm(text);
						else if(tagName.equals("gpsX"))
							objectToAdd.setGpsX(text);
						else if(tagName.equals("gpsY"))
							objectToAdd.setGpsY(text);
						else if(tagName.equals("stationTp"))
							objectToAdd.setStationTp(text);
						else if(tagName.equals("firstTm"))
							objectToAdd.setFirstTm(text);
						else if(tagName.equals("lastTm"))
							objectToAdd.setLastTm(text);
						else if(tagName.equals("term"))
							objectToAdd.setTerm(text);
						else if(tagName.equals("routeType"))
							objectToAdd.setRouteType(text);
						else if(tagName.equals("nextBus"))
							objectToAdd.setNextBus(text);
						else if(tagName.equals("staOrd"))
							objectToAdd.setStaOrd(text);
						else if(tagName.equals("vehId1"))
							objectToAdd.setVehId1(text);
						else if(tagName.equals("plainNo1"))
							objectToAdd.setPlainNo1(text);
						else if(tagName.equals("sectOrd1"))
							objectToAdd.setSectOrd1(text);
						else if(tagName.equals("stationNm1"))
							objectToAdd.setStationNm1(text);
						else if(tagName.equals("traTime1"))
							objectToAdd.setTraTime1(text);
						else if(tagName.equals("traSpd1"))
							objectToAdd.setTraSpd1(text);
						else if(tagName.equals("isArrive1"))
							objectToAdd.setIsArrive1(text);
						else if(tagName.equals("repTm1"))
							objectToAdd.setRepTm1(text);
						else if(tagName.equals("isLast1"))
							objectToAdd.setIsLast1(text);
						else if(tagName.equals("busType1"))
							objectToAdd.setBusType1(text);
						else if(tagName.equals("vehId2"))
							objectToAdd.setVehId2(text);
						else if(tagName.equals("plainNo2"))
							objectToAdd.setPlainNo2(text);
						else if(tagName.equals("sectOrd2"))
							objectToAdd.setSectOrd2(text);
						else if(tagName.equals("stationNm2"))
							objectToAdd.setStationNm2(text);
						else if(tagName.equals("traTime2"))
							objectToAdd.setTraTime2(text);
						else if(tagName.equals("traSpd2"))
							objectToAdd.setTraSpd2(text);
						else if(tagName.equals("isArrive2"))
							objectToAdd.setIsArrive2(text);
						else if(tagName.equals("repTm2"))
							objectToAdd.setRepTm2(text);
						else if(tagName.equals("isLast2"))
							objectToAdd.setIsLast2(text);
						else if(tagName.equals("busType2"))
							objectToAdd.setBusType2(text);
					}

					break;
				}

				parserEvent = parser.next();
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		
		return result;
	}

}
